<template>
  <div class="bg">
    <!-- 中间的盒子 -->
    <div class="centerBox">
      <!-- 标题 -->
      <div class="titleBox">医院预约挂号系统</div>
      <!-- 用户名 -->
      <div style="margin-bottom: 20px;">
        <el-input v-model="username" placeholder="请输入用户名">
          <template slot="prepend">
            <i class="el-icon-user"></i>
          </template>
        </el-input>
      </div>
      <!-- 密码 -->
      <div style="margin-bottom: 20px;">
        <el-input v-model="password" placeholder="请输入密码" show-password="false">
          <template slot="prepend">
            <i class="el-icon-lock"></i>
          </template>
        </el-input>
      </div>

      <div style="margin-bottom: 20px; text-align: center">
        <el-radio v-model="radio" label="ADMIN">管理员</el-radio>
        <el-radio v-model="radio" label="DOCTOR">医生</el-radio>
        <el-radio v-model="radio" label="USER">患者</el-radio>
      </div>
      <!-- 登录按钮 -->
      <div style="text-align: center; margin-bottom: 20px;">
        <el-button type="primary" style="width: 100%;" @click="login">登录</el-button>
      </div>
      <!-- 注册 -->
      <div class="register" @click="register()">
        立即注册
      </div>
    </div>
  </div>
</template>

<script>
import axios from "axios";
import request from "@/utils/request";
export default {
  data() {
    return {
      username: "",
      password: "",
      radio: "USER"
    };
  },
  methods: {
    //登录按钮
    login() {
      // alert("登录")
      //发送请求
      request.post("/login?account="  + this.username + "&password=" + this.password + "&role=" + this.radio ).then(res => {
        console.log(res);
        if(res.code == 200){
          localStorage.setItem("user",JSON.stringify(res.data))
          this.$router.replace({path:'/'})
          this.$message({
            message:"登录成功!",
            type:"success"
          })
        }else{
          this.$message({
            message: res.msg,
            type: "error"
          });
        }
      })
    },

    //register
    register(){
      this.$router.push({path:'/register'})
    }
  }
};
</script>

<style>
.bg {
  height: 100vh;
  background-color: #c9e3fa;
  overflow: hidden;
}
.bg .centerBox {
  margin: 200px auto;
  width: 360px;
  height: 320px;
  background-color: #c9e3fa;
}
.titleBox {
  /* background-color: pink; */
  height: 70px;
  line-height: 70px;
  color: #1e90ff;
  font-weight: 800;
  font-size: 26px;
  text-align: center;
}
.register {
  float: right;
}
.register{
  text-decoration: none;
  color: #958b2f;
}
.forgetPassword a {
  text-decoration: none;
  color: #958b2f;
}
</style>